export default class Key {
    static keys: WeakSet<Key> = new Set();

    static factory(name?: string): Key {
        !name && (name = 'Global Name')

        let val = new Key(name)
        this.keys.add(val)
        return val
    }

    static findKey(param: Key) {
        if (this.keys.has(param)) {
            return param.name
        } else {
            throw new Error('Illegal creation Key')
        }
    }

    constructor(name: string) {
        this.setName(name)
    }

    private name!: string

    private setName(val: string) {
        this.name = val
    }
}